var e, a = require("@vant/area-data"), t = (e = require("@vant/weapp/toast/toast")) && e.__esModule ? e : {
    default: e
};

var s = getApp(), i = require("../../utils/api"), n = require("../../utils/request"), o = require("../../utils/check"), c = require("../../utils/storage");

Page({
    data: {
        themeColor: s.globalData.themeColor,
        areaList: a.areaList,
        checkNo: "",
        filmPriceData: [],
        filmPrintData: [],
        showFilmPrintData: [],
        showFilmPrintContent: !1,
        collapseChecked: [ "1" ],
        checkedFilmPrintSfxm: [],
        checkedTakeFilmPrintTypeTab: "1",
        totalPrice: 0,
        printType: "1",
        printTypeName: "寄送个人",
        baseInfoCheckUserOpenId: "",
        baseInfoCheckTime: "",
        baseInfoCheckUserName: "",
        baseInfoCheckUserMobile: "",
        baseInfoCheckUserCompanyCode: "",
        baseInfoCheckUserCompanyName: "",
        baseInfoCheckInsCode: "",
        takeFilmType: null,
        sendInfoUserName: "",
        sendInfoUserMobile: "",
        sendInfoArea: "",
        sendInfoAddress: "",
        canPickSelf: !1,
        pickSelfInsCode: "",
        pickSelfInsName: "",
        pickSelfInsAddress: "",
        pickSelfInsTel: "",
        pickSelfUserMobile: "",
        electronicInfoUserMobile: "",
        showSelectAreaPopup: !1,
        showTakeFilmActionSheet: !1,
        takeFilmActions: [ {
            name: "寄送个人"
        }, {
            name: "到店自取"
        } ],
        submitLoading: !1
    },
    onLoad: function(e) {
        this.setData({
            checkNo: e.checkNo
        }), this.getFilmPrint(e.checkNo), this.getCheckInfo(e.checkNo);
    },
    getCheckInfo: function(e) {
        var a = this;
        wx.showLoading({
            title: "加载中",
            mask: !0
        }), n.request(n.HttpMethod.GET, i.apiRoute.getFilmPrintCheckInfoByCheckNo + e, {}).then(function(e) {
            "20000" == e.code && (wx.hideLoading(), a.setData({
                baseInfoCheckUserOpenId: c.getStorageSync(c.storageKey.openId),
                baseInfoCheckTime: e.data.checkUserCheckTime,
                baseInfoCheckUserName: e.data.checkUserName,
                baseInfoCheckUserMobile: e.data.checkUserMobile,
                baseInfoCheckUserCompanyCode: e.data.checkUserCompanyCode,
                baseInfoCheckUserCompanyName: e.data.checkUserCompanyName,
                baseInfoCheckInsCode: e.data.checkInsCode,
                sendInfoUserName: e.data.checkUserName,
                sendInfoUserMobile: e.data.checkUserMobile,
                sendInfoArea: "",
                sendInfoAddress: "",
                canPickSelf: e.data.canPrint,
                pickSelfInsCode: e.data.canPrintInsCode,
                pickSelfInsName: e.data.canPrintInsName,
                pickSelfInsAddress: e.data.canPrintInsAddress,
                pickSelfInsTel: e.data.canPrintInsPhone,
                pickSelfUserMobile: e.data.checkUserMobile,
                electronicInfoUserMobile: e.data.checkUserMobile
            }));
        }).catch(function() {
            wx.hideLoading(), (0, t.default)({
                message: "获取体检信息异常",
                duration: 5e3
            });
        });
    },
    getFilmPrint: function(e) {
        var a = this;
        wx.showLoading({
            title: "加载中",
            mask: !0
        }), n.request(n.HttpMethod.GET, i.apiRoute.getFilmPrintDataByCheckNo + e, {}).then(function(e) {
            if ("20000" == e.code) {
                var t = !1, s = [];
                null != e.data && e.data.length > 0 && (t = !0, a.data.collapseChecked = e.data[0].jcks, 
                e.data.forEach(function(e) {
                    e.ks.forEach(function(a) {
                        s.push({
                            jcks: e.jcks,
                            ksmc: e.ksmc,
                            sfxm: a.sfxm,
                            sfmc: a.sfmc,
                            jpsl: a.jpsl,
                            jpje: a.jpje
                        });
                    });
                })), a.setData({
                    filmPrintData: e.data,
                    showFilmPrintData: e.data,
                    showFilmPrintContent: t,
                    filmPriceData: s
                });
            }
        }).catch(function(e) {
            console.log(e), wx.hideLoading(), (0, t.default)({
                message: "获取可打印胶片信息异常",
                duration: 5e3
            });
        });
    },
    onCollapseChange: function(e) {
        this.setData({
            collapseChecked: e.detail
        });
    },
    onCheckedChange: function(e) {
        var a = 0;
        "1" == this.data.checkedTakeFilmPrintTypeTab && this.data.filmPriceData.forEach(function(t) {
            e.detail.indexOf(t.sfxm) > -1 && (a += t.jpje * t.jpsl);
        }), this.setData({
            checkedFilmPrintSfxm: e.detail,
            totalPrice: a
        });
    },
    onTabChange: function(e) {
        if (console.log(e.detail), "2" == e.detail.name) {
            var a = this.data.filmPrintData.filter(function(e) {
                return e.showInElectron;
            });
            this.setData({
                showFilmPrintData: a
            });
        } else this.setData({
            showFilmPrintData: this.data.filmPrintData
        });
        this.setData({
            checkedTakeFilmPrintTypeTab: e.detail.name,
            checkedFilmPrintSfxm: [],
            totalPrice: 0
        });
    },
    onOpenSelectArea: function() {
        this.setData({
            showSelectAreaPopup: !0
        });
    },
    onCloseSelectArea: function() {
        this.setData({
            showSelectAreaPopup: !1
        });
    },
    confirmSelectArea: function(e) {
        var a = "", s = e.detail.values, i = !0;
        s.forEach(function(e) {
            null != e && null != e.code && null != e.name && "" != e.code && "" != e.name ? a += e.name + " " : i = !1;
        }), i ? this.setData({
            showSelectAreaPopup: !1,
            sendInfoArea: a
        }) : (0, t.default)({
            message: "请选择完整的省市区",
            duration: 5e3
        });
    },
    onOpenTakeFilmActionSheet: function() {
        this.setData({
            showTakeFilmActionSheet: !0
        });
        var e = this;
        wx.showActionSheet({
            itemList: [ "寄送个人", "到店自取" ],
            itemColor: e.data.themeColor,
            success: function(a) {
                "showActionSheet:ok" == a.errMsg && (0 == a.tapIndex ? e.setData({
                    printType: "1",
                    printTypeName: "寄送个人"
                }) : 1 == a.tapIndex && e.setData({
                    printType: "2",
                    printTypeName: "到店自取"
                }));
            }
        });
    },
    createFilmPrint: function() {
        var e = this;
        if (this.data.checkedFilmPrintSfxm.length <= 0) (0, t.default)({
            message: "请选择需要的胶片",
            duration: 5e3
        }); else {
            var a = [];
            if (this.data.filmPriceData.forEach(function(t) {
                e.data.checkedFilmPrintSfxm.indexOf(t.sfxm) > -1 && a.push(t);
            }), "1" == this.data.checkedTakeFilmPrintTypeTab) {
                if ("1" != this.data.printType && "2" != this.data.printType) return void (0, t.default)({
                    message: "请选择取片方式",
                    duration: 5e3
                });
                if ("1" == this.data.printType) {
                    if (null == this.data.sendInfoUserName || null == this.data.sendInfoUserName || "" == this.data.sendInfoUserName) return void (0, 
                    t.default)({
                        message: "寄送个人姓名不能为空",
                        duration: 5e3
                    });
                    if (null == this.data.sendInfoUserMobile || null == this.data.sendInfoUserMobile || "" == this.data.sendInfoUserMobile) return void (0, 
                    t.default)({
                        message: "寄送个人手机号不能为空",
                        duration: 5e3
                    });
                    if (!o.isMobile(this.data.sendInfoUserMobile)) return void (0, t.default)({
                        message: "寄送个人手机号不正确",
                        duration: 5e3
                    });
                    if (null == this.data.sendInfoArea || null == this.data.sendInfoArea || "" == this.data.sendInfoArea) return void (0, 
                    t.default)({
                        message: "寄送个人地区不能为空",
                        duration: 5e3
                    });
                    if (null == this.data.sendInfoAddress || null == this.data.sendInfoAddress || "" == this.data.sendInfoAddress) return void (0, 
                    t.default)({
                        message: "寄送个人详细地址不能为空",
                        duration: 5e3
                    });
                    this.setData({
                        showDialog: !0
                    });
                }
                if ("2" == this.data.printType) {
                    if (!this.data.canPickSelf) return void (0, t.default)({
                        message: "您所在体检机构暂不支持到店自取",
                        duration: 5e3
                    });
                    if (null == this.data.pickSelfUserMobile || null == this.data.pickSelfUserMobile || "" == this.data.pickSelfUserMobile) return void (0, 
                    t.default)({
                        message: "到店自取手机号不能为空",
                        duration: 5e3
                    });
                    if (!o.isMobile(this.data.pickSelfUserMobile)) return void (0, t.default)({
                        message: "到店自取手机号不正确",
                        duration: 5e3
                    });
                    this.setData({
                        showDialog: !0
                    });
                }
            } else {
                if (null == this.data.electronicInfoUserMobile || null == this.data.electronicInfoUserMobile || "" == this.data.electronicInfoUserMobile) return void (0, 
                t.default)({
                    message: "电子胶片接收通知手机号不能为空",
                    duration: 5e3
                });
                if (!o.isMobile(this.data.electronicInfoUserMobile)) return void (0, t.default)({
                    message: "电子胶片接收通知手机号不正确",
                    duration: 5e3
                });
                this.setData({
                    submitLoading: !0
                }), n.request(n.HttpMethod.POST, i.apiRoute.createFilmPrint, {
                    checkUserOpenId: this.data.baseInfoCheckUserOpenId,
                    checkNo: this.data.checkNo,
                    checkTime: this.data.baseInfoCheckTime,
                    checkUserName: this.data.baseInfoCheckUserName,
                    checkUserMobile: this.data.baseInfoCheckUserMobile,
                    checkUserCompanyCode: this.data.baseInfoCheckUserCompanyCode,
                    checkUserCompanyName: this.data.baseInfoCheckUserCompanyName,
                    checkInsCode: this.data.baseInfoCheckInsCode,
                    takeFilmType: 2,
                    sendUserName: "",
                    sendUserMobile: "",
                    sendArea: "",
                    sendAddress: "",
                    pickSelfInsCode: "",
                    pickSelfUserMobile: "",
                    electronicUserMobile: this.data.electronicInfoUserMobile,
                    totalFee: 0,
                    filmPrintDetailCreateRequestList: a
                }).then(function(a) {
                    e.setData({
                        submitLoading: !1
                    }), a.success ? wx.navigateTo({
                        url: "/pages/film-print-list/film-print-list?active=1",
                        success: function() {}
                    }) : (0, t.default)({
                        message: a.message,
                        duration: 5e3
                    });
                }).catch(function(a) {
                    e.setData({
                        submitLoading: !1
                    }), console.log(a), (0, t.default)({
                        message: "创建订单异常",
                        duration: 5e3
                    });
                });
            }
        }
    },
    onDialogConfirm: function() {
        var e = this;
        this.setData({
            showDialog: !1
        });
        var a = [];
        this.data.filmPriceData.forEach(function(t) {
            e.data.checkedFilmPrintSfxm.indexOf(t.sfxm) > -1 && a.push(t);
        }), "1" == this.data.checkedTakeFilmPrintTypeTab && ("1" == this.data.printType && (this.setData({
            submitLoading: !0
        }), n.request(n.HttpMethod.POST, i.apiRoute.createFilmPrint, {
            checkUserOpenId: this.data.baseInfoCheckUserOpenId,
            checkNo: this.data.checkNo,
            checkTime: this.data.baseInfoCheckTime,
            checkUserName: this.data.baseInfoCheckUserName,
            checkUserMobile: this.data.baseInfoCheckUserMobile,
            checkUserCompanyCode: this.data.baseInfoCheckUserCompanyCode,
            checkUserCompanyName: this.data.baseInfoCheckUserCompanyName,
            checkInsCode: this.data.baseInfoCheckInsCode,
            takeFilmType: 0,
            sendUserName: this.data.sendInfoUserName,
            sendUserMobile: this.data.sendInfoUserMobile,
            sendArea: this.data.sendInfoArea,
            sendAddress: this.data.sendInfoAddress,
            pickSelfInsCode: "",
            pickSelfUserMobile: "",
            electronicUserMobile: "",
            totalFee: this.data.totalPrice,
            filmPrintDetailCreateRequestList: a
        }).then(function(a) {
            e.setData({
                submitLoading: !1
            }), a.success ? wx.navigateTo({
                url: "/pages/webview/webview?h5=".concat(encodeURIComponent(a.data.payUrl)),
                success: function() {}
            }) : (0, t.default)({
                message: a.message,
                duration: 5e3
            });
        }).catch(function(a) {
            e.setData({
                submitLoading: !1
            }), console.log(a), (0, t.default)({
                message: "创建订单异常",
                duration: 5e3
            });
        })), "2" == this.data.printType && (this.setData({
            submitLoading: !0
        }), n.request(n.HttpMethod.POST, i.apiRoute.createFilmPrint, {
            checkUserOpenId: this.data.baseInfoCheckUserOpenId,
            checkNo: this.data.checkNo,
            checkTime: this.data.baseInfoCheckTime,
            checkUserName: this.data.baseInfoCheckUserName,
            checkUserMobile: this.data.baseInfoCheckUserMobile,
            checkUserCompanyCode: this.data.baseInfoCheckUserCompanyCode,
            checkUserCompanyName: this.data.baseInfoCheckUserCompanyName,
            checkInsCode: this.data.baseInfoCheckInsCode,
            takeFilmType: 1,
            sendUserName: "",
            sendUserMobile: "",
            sendArea: "",
            sendAddress: "",
            pickSelfInsCode: this.data.pickSelfInsCode,
            pickSelfUserMobile: this.data.pickSelfUserMobile,
            electronicUserMobile: "",
            totalFee: this.data.totalPrice,
            filmPrintDetailCreateRequestList: a
        }).then(function(a) {
            e.setData({
                submitLoading: !1
            }), a.success ? wx.navigateTo({
                url: "/pages/webview/webview?h5=".concat(encodeURIComponent(a.data.payUrl)),
                success: function() {}
            }) : (0, t.default)({
                message: a.message,
                duration: 5e3
            });
        }).catch(function(a) {
            e.setData({
                submitLoading: !1
            }), console.log(a), (0, t.default)({
                message: "创建订单异常",
                duration: 5e3
            });
        })));
    },
    onDialogCancel: function() {
        this.setData({
            showDialog: !1
        });
    }
});